package com.qyhl.party.party.supplement.department;

import android.content.Intent;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.party.R;
import com.qyhl.party.R2;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterPathConstant.PARTY_SUPPLEMENT_DEPARTMENT)
public class PartyDepartmentActivity extends BaseActivity {
    @BindView(R2.id.tab_layout)
    SlidingTabLayout tabLayout;
    @BindView(R2.id.view_pager)
    ViewPager viewPager;

    @Autowired(name = "depId")
    int depId;

    @Override
    protected int getContentView() {
        return R.layout.party_activity_department;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {

    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        List<String> nameList = new ArrayList<>();
        List<Fragment> fragmentList = new ArrayList<>();
        nameList.add("部门/企业");
        nameList.add("乡镇/街道");
        nameList.add("村/社区");

        fragmentList.add(PartyDepartmentFragment.newInstance(depId, 2));
        fragmentList.add(PartyDepartmentFragment.newInstance(depId, 3));
        fragmentList.add(PartyDepartmentFragment.newInstance(depId, 4));
        viewPager.setAdapter(new Adapter(getSupportFragmentManager(), fragmentList, nameList));
        tabLayout.setViewPager(viewPager);
    }

    @Override
    protected void setListener() {

    }

    @OnClick(R2.id.back_btn)
    public void onClick() {
        finish();
    }

    public void doFinish(int depId, String name) {
        Intent intent = new Intent();
        intent.putExtra("depId", depId);
        intent.putExtra("name", name);
        setResult(RESULT_OK, intent);
        finish();
    }

    static class Adapter extends FragmentPagerAdapter {
        private List<Fragment> fragmentList;
        private List<String> names;

        Adapter(FragmentManager fm, List<Fragment> fragmentList, List<String> names) {
            super(fm);
            this.fragmentList = fragmentList;
            this.names = names;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names.get(position);
        }
    }

}
